package jpavlich.cardsorter;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;

import net.miginfocom.swing.MigLayout;
import javax.swing.ListSelectionModel;

public class ExperimentsDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JList experimentList;

	/**
	 * Create the dialog.
	 */
	public ExperimentsDialog(final ExperimentsListModel expsListModel) {
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
	        @Override public void windowClosing(WindowEvent e) {
	            System.exit(0);
	        }
	    });
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new MigLayout("", "[fill][][][grow,fill]", "[51px,grow][]"));
		{
			JScrollPane scrollPane = new JScrollPane();
			contentPanel.add(scrollPane, "cell 0 0 4 1,grow");
			{
				experimentList = new JList();
				experimentList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
				scrollPane.setViewportView(experimentList);
				experimentList.setModel(expsListModel);
			}
		}
		{
			JButton btnNuevoExperimento = new JButton("Nuevo experimento");
			btnNuevoExperimento.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Controller.newExperimentDialog();
				}

			});
			contentPanel.add(btnNuevoExperimento, "cell 0 1,alignx left,aligny center");
		}
		{
			JButton btnBorrarExperimiento = new JButton("Borrar");
			btnBorrarExperimiento.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				}
			});
			{
				JButton btnReproducir = new JButton("Reproducir");
				btnReproducir.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						Controller.playExperiment(experimentList);
					}
				});
				contentPanel.add(btnReproducir, "cell 1 1");
			}
			contentPanel.add(btnBorrarExperimiento, "cell 2 1");
		}
	}

}
